import java.io.*;

public class test1 {
    public static void main(String[] args) throws IOException {
        File src = new File("Java_11_16\\aaa");

        File dest = new File("Java_11_16\\bbb");

        copyDir(src, dest);
    }

    public static void copyDir(File src, File dest) throws IOException {
        dest.mkdir();
        File[] files = src.listFiles();
        //src可能因为权限无法访问导致files为空指针进而导致下面遍历报错,不过这里不用担心
        for (File f : files) {
            if (f.isFile()) {
                FileInputStream fis = new FileInputStream(f);
                FileOutputStream fos = new FileOutputStream(new File(dest,f.getName()));
                byte[] chars = new byte[1024 * 1024 * 5];
                int len;
                while ((len = fis.read(chars)) != -1) {
                    fos.write(chars, 0, len);
                }
                fos.close();
                fis.close();
            } else {
                copyDir(f, new File(dest,f.getName()));
            }
        }
    }

}
